gh-143923: Reject control characters in POP3 commands
authorSeth Michael Larson <seth@python.org>
Tue, 20 Jan 2026 20:46:32 +0000 (14:46 -0600)
committerAndrej Shadura <andrewsh@debian.org>
Sun, 25 Jan 2026 13:37:52 +0000 (14:37 +0100)
Origin: backport, https://github.com/python/cpython/commit/b234a2b67539f787e191d2ef19a7cbdce32874e7

Gbp-Pq: Name CVE-2025-15367.patch

Lib/poplib.py
Lib/test/test_poplib.py
Misc/NEWS.d/next/Security/2026-01-16-11-43-47.gh-issue-143923.DuytMe.rst [new file with mode: 0644]

index 0f8587317c2bbc4c37c79b9112ffc281c67bcebd..f563030f7f3c0e04cf72f4c2fda65cd74187f388 100644 (file)
@@ -122,6 +122,8 @@ class POP3:
     def _putcmd(self, line):
         if self._debugging: print('*cmd*', repr(line))
         line = bytes(line, self.encoding)
+        if re.search(b'[\x00-\x1F\x7F]', line):
+            raise ValueError('Control characters not allowed in commands')
         self._putline(line)
 
 
index b670afcf4e62eeb626164ef45925cb6d14d268e2..f69ac471e4de246c6ed2ff5f75f9a3fc56956d58 100644 (file)
@@ -15,6 +15,8 @@ from unittest import TestCase, skipUnless
 from test import support as test_support
 from test.support import hashlib_helper
 from test.support import socket_helper
+from test.support import control_characters_c0
+
 
 HOST = socket_helper.HOST
 PORT = 0
@@ -359,6 +361,13 @@ class TestPOP3Class(TestCase):
         self.assertIsNone(self.client.sock)
         self.assertIsNone(self.client.file)
 
+    def test_control_characters(self):
+        for c0 in control_characters_c0():
+            with self.assertRaises(ValueError):
+                self.client.user(f'user{c0}')
+            with self.assertRaises(ValueError):
+                self.client.pass_(f'{c0}pass')
+
     @requires_ssl
     def test_stls_capa(self):
         capa = self.client.capa()
diff --git a/Misc/NEWS.d/next/Security/2026-01-16-11-43-47.gh-issue-143923.DuytMe.rst b/Misc/NEWS.d/next/Security/2026-01-16-11-43-47.gh-issue-143923.DuytMe.rst
new file mode 100644 (file)
index 0000000..3cde4df
--- /dev/null
@@ -0,0 +1 @@
+Reject control characters in POP3 commands.